package com.bcu.calculus.service.serviceImpl;

import com.bcu.calculus.entity.Message;
import com.bcu.calculus.utils.SendUtil;
import com.bcu.calculus.entity.Tlist;
import com.bcu.calculus.mapper.TlistMapper;
import com.bcu.calculus.service.TlistService;
import org.apache.commons.io.output.ClosedOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class TlistServiceImpl implements TlistService {
    private Logger logger= LoggerFactory.getLogger(getClass());

    @Resource
    private TlistMapper tlistMapper;

    @Override
    public Message<?> addTlist(Tlist tlist) {
        tlist.setTlistPostTime(new Date());
        String tlistId = "TL" + SendUtil.genSendId();
        tlist.setTlistId(tlistId);
        logger.info("三级标题-----增加三级标题,tlistId为 "+tlist.getTlistId());
        return tlistMapper.insertSelective(tlist) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> delTlist(String tlistId) {
        logger.info("三级标题-----删除三级标题,tlistId为 "+tlistId);
        return tlistMapper.deleteByPrimaryKey(tlistId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> updateTlist(Tlist tlist) {
        logger.info("三级标题-----修改三级标题,tlistId为 "+tlist.getTlistId());
        return tlistMapper.updateByPrimaryKeySelective(tlist) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<Tlist> selectOneTlistById(String tlistId) {
        logger.info("三级标题-----通过tlistId查找,listId为 "+tlistId);
        return Message.success(null).add(tlistMapper.selectByPrimaryKey(tlistId));
    }

    @Override
    public Message<List<Tlist>> selectAllTlist() {
        logger.info("三级标题-----查找全部");
        return Message.success(null).add(tlistMapper.selectAll());
    }

    @Override
    public Message<List<Tlist>> getTlistBySlistId(String slistId) {
        logger.info("三级标题-----通过二级标题获得三级标题,slistId为 "+slistId);
        return Message.success(null).add(tlistMapper.getTlistBySlistId(slistId));
    }

    @Override
    public Message<List<Tlist>> getTlistByuserType(String userType) {
        logger.info("三级标题-----通过负责人类型得到三级标题,userType为 "+userType);
        return Message.success(null).add(tlistMapper.getTlistByUserType(userType));
    }

}
